<!--
 * @Author: your name
 * @Date: 2021-03-29 17:17:33
 * @LastEditTime: 2021-03-31 15:33:13
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \shop\training-group-5-warehouse\dianshang\src\views\Bargain\components\Dirlogs.vue
-->
<template>
  <div class="dirlogs" v-if="isShow">
    <div class="container">
      <div class="addCity" v-show="type==='addCity'">
        <div class="cancel" @click="handleCancel">X</div>请先
        <span @click="handleAddCitys">添加地址</span>
      </div>
      <div class="goldKnife" v-show="type==='goldKnife'" v-if="tabIsShow===false">
        <div class="cancel" @click="handleCancel">X</div>
        <img :src="bargainDirlogs" alt />
        <div
          style="flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;"
        >
          <span>金刀砍一砍</span>
          <span>帮助自己先砍一刀</span>
        </div>
        <button
          style="
          border-radius: 10px; 
          width: 100%; 
          height: 40px;  
          background: -webkit-linear-gradient(#feac1c, #ff892f);
          border: none;
          outline: none;
          color: #fff;
          margin-bottom: 20px;
          "
          @click="handleUserBargain"
        >点击砍价</button>
      </div>
      <div class="goldKnife" v-show="type==='goldKnife'" v-if="tabIsShow===true">
        <div class="cancel" @click="handlePushInvitation">X</div>
        <img :src="bargainDirlogs" alt />
        <div
          style="flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;"
        >
          <span>恭喜！金刀砍一砍砍掉</span>
          <span>
            <b
              style="color: red; font-size: 26px; margin-top: 10px;"
              v-text="(shopItem.price * '0.97').toString().slice(0,6)"
            ></b>
            元
          </span>
          <div class="progressBar">
            <span>仅剩00.3%</span>
          </div>
        </div>
        <button
          style="
          border-radius: 10px; 
          width: 100%; 
          height: 40px;  
          background: -webkit-linear-gradient(#feac1c, #ff892f);
          border: none;
          outline: none;
          color: #fff;
          margin-bottom: 20px;
          "
          @click="handleWeChatShow"
        >继续分享给好友帮砍</button>
      </div>
    </div>

    <div class="goToWeChat" v-if="WeChatShow">
      <div class="container">
        <div class="cloneWeChat">
          <div
            class="cancel"
            @click="()=>WeChatShow = false"
            style="background: #ccc; color: #333;"
          >X</div>
          <div
            style="width: 100%; height: 150px;  display: flex; align-items: center; justify-content: center; margin: 10px 0;"
          >
            <img :src="shibbolethImg" alt style="width: 130px; height: 100px;" />
          </div>
          <div
            style="width: 100%; height: 100px; display: flex;  flex-direction: column; align-items: center; justify-content: center;"
          >
            <p style="margin: 5px 0;">去微信粘贴给好友</p>
            <p>
              好友帮砍后可
              <span style="color: red;">砍大金额</span>
            </p>
          </div>
          <div
            style="width: 100%; height: 150px;  display: flex; align-items: center; justify-content: center;"
          >
            <img
              :src="weChatBtnImg"
              alt
              style="width: 260px; height: 55px;"
              @click="handleClonePushWeChat"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import bargainDirlogs from "../../../assets/img/bargain-dirlogs_03.jpg";
import shibbolethImg from "../../../assets/img/shibbolethImg.jpg";
import weChatBtnImg from "../../../assets/img/weChatBtnImg.jpg";
import { mapMutations, mapState } from "vuex";
export default {
  props: {
    //组件显示隐藏
    isShow: {
      type: Boolean,
      require: true,
      default: false,
    },
    //组件类型
    type: {
      type: String,
      require: true,
      default: "",
    },
    //砍价每一项
    shopItem: {
      type: Object,
      require: true,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      weChatBtnImg: weChatBtnImg, //微信按钮图片
      shibbolethImg: shibbolethImg, //口令复制图片
      bargainDirlogs: bargainDirlogs,
      tabIsShow: false, //页面显示状态
      WeChatShow: false, //微信分享开关
    };
  },
  computed: {
    ...mapState("login", ["userInfo"]),
  },
  methods: {
    ...mapMutations("bargain", [
      "SET_SHOPITEM",
      "SET_SHOPBARGAIN",
      "SET_LOCALHOST",
    ]),
    handleAddCitys() {
      this.$emit("handleAddCity"); //请先添加地址
    },
    handleCancel() {
      this.$emit("handleCancel"); //Dirlogs弹框隐藏
    },
    //跳转邀请好友砍价
    handlePushInvitation() {
      this.tabIsShow = false;
      this.handleCancel();
      this.SET_SHOPITEM(this.shopItem);
      this.$router.push("/invitation");
    },
    //帮助自己砍价
    handleUserBargain() {
      this.tabIsShow = true;
      this.SET_SHOPBARGAIN(this.userInfo);
    },
    //弹出微信分享弹框
    handleWeChatShow() {
      this.WeChatShow = true;
    },
    //复制指令去微信页面
    handleClonePushWeChat() {
      this.SET_LOCALHOST("http://localhost:4000/bargain");
      this.$router.push({
        path: "/weChat",
        query: { url: "http://localhost:4000/bargain" },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.dirlogs {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  position: fixed;
  left: 0;
  top: 0;
  .cancel {
    width: 30px;
    height: 30px;
    background: #eed59c;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: -15px;
    top: -15px;
    font-size: 20px;
    color: #cbb27b;
    z-index: 999;
  }
  .container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    .addCity {
      width: 275px;
      height: 210px;
      background: #fff;
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
      font-weight: 600;
      border-radius: 20px;
      span {
        color: royalblue;
        border-bottom: solid 1px royalblue;
      }
    }
    .goldKnife {
      width: 275px;
      height: 210px;
      background: -webkit-linear-gradient(#fff5e3, #ffeeca);
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      font-size: 16px;
      font-weight: 600;
      border-radius: 20px;
      padding: 0 20px;
      img {
        position: absolute;
        left: 0;
        top: -71px;
      }
      span {
        margin: 5px 0;
        font-size: 18px;
        color: #583617;
      }
    }
  }
}
.goToWeChat {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  .container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    .cloneWeChat {
      width: 300px;
      height: 300px;
      background: #fff;
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      font-size: 16px;
      font-weight: 600;
      border-radius: 20px;
      padding: 0 20px;
    }
  }
}
.progressBar {
  width: 100%;
  height: 10px;
  background: #f6b70a;
  border-radius: 10px;
  position: relative;
  span {
    position: absolute;
    right: -35px;
    top: -25px;
    background: red;
    color: #fff !important;
    font-size: 12px !important;
    border-radius: 3px;
  }
}
</style>